package com.nobody.facepk.model;

import java.lang.reflect.Type;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.nobody.facepk.persist.PersistentSupport;
import com.nobody.facepk.pojo.JsonHelper;

@Entity
@Table(name = "T_PIC_DATA")
public class PictureData extends PersistentSupport{
	private Long pictureId;
	private PictureDataType type;
	private String data;
	
	public PictureData() {}
	
	public PictureData(Long pictureId, PictureDataType type) {
		this.pictureId = pictureId;
		this.type = type;
	}
	
	public Long getPictureId() {
		return this.pictureId;
	}

	public void setPictureId(Long pictureId) {
		this.pictureId = pictureId;
	}

	public PictureDataType getType() {
		return this.type;
	}

	public void setType(PictureDataType type) {
		this.type = type;
	}

	public String getData() {
		return this.data;
	}
	public void setData(String data) {
		this.data = data;
	}
	
	@Transient
	public <T> T getData(Class<T> clazz) {
		return JsonHelper.parse(clazz, this.data);
	}
	
	@Transient
	public <T> List<T> getDataAsList(Type type) {
		return JsonHelper.parseAsList(type, this.data);
	}
	
	@Transient
	public void setData(Object o) {
		this.data = JsonHelper.toGson(o);
	}
}
